<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Robocup-denayer-project-a: read-only/trunk/source/serial2/test.cpp Bron Bestand</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javaScript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Gegenereerd door Doxygen 1.7.1 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Zoeken');
--></script>
<script type="text/javascript">
function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function toggleVisibility(linkObj) {
 var base = linkObj.getAttribute('id');
 var summary = document.getElementById(base + '-summary');
 var content = document.getElementById(base + '-content');
 var trigger = document.getElementById(base + '-trigger');
 if ( hasClass(linkObj,'closed') ) {
   summary.style.display = 'none';
   content.style.display = 'block';
   trigger.src = 'open.png';
   removeClass(linkObj,'closed');
   addClass(linkObj,'opened');
 } else if ( hasClass(linkObj,'opened') ) {
   summary.style.display = 'block';
   content.style.display = 'none';
   trigger.src = 'closed.png';
   removeClass(linkObj,'opened');
   addClass(linkObj,'closed');
 }
 return false;
}
</script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Hoofd&nbsp;Pagina</span></a></li>
      <li><a href="annotated.html"><span>Klassen</span></a></li>
      <li class="current"><a href="files.html"><span>Bestanden</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
          <span class="left">
            <form id="FSearchBox" action="search.php" method="get">
              <img id="MSearchSelect" src="search/mag.png" alt=""/>
              <input type="text" id="MSearchField" name="query" value="Zoeken" size="20" accesskey="S" 
                     onfocus="searchBox.OnSearchFieldFocus(true)" 
                     onblur="searchBox.OnSearchFieldFocus(false)"/>
            </form>
          </span><span class="right"></span>
        </div>
      </li>
    </ul>
  </div>
  <div class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&nbsp;Lijst</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>read-only/trunk/source/serial2/test.cpp</h1>  </div>
</div>
<div class="contents">
<a href="test_8cpp.html">Ga naar de documentatie van dit bestand.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00002"></a><a class="code" href="test_8cpp.html#a031fc8d9a2aec0a2af2b3c9884e277e4">00002</a> <span class="preprocessor">#define POORT 0</span>
<a name="l00003"></a><a class="code" href="test_8cpp.html#a5dd13af014b612f67220ddd841479c5b">00003</a> <span class="preprocessor"></span><span class="preprocessor">#define MAXV 0x40</span>
<a name="l00004"></a>00004 <span class="preprocessor"></span>
<a name="l00005"></a>00005 <span class="keyword">using namespace </span>std;
<a name="l00006"></a>00006 <span class="preprocessor">#include &quot;<a class="code" href="rs232_8h.html">rs232.h</a>&quot;</span>
<a name="l00007"></a>00007 
<a name="l00008"></a><a class="code" href="test_8cpp.html#a45b838daf06782e49813fb7631e957ec">00008</a> <span class="keywordtype">void</span> <a class="code" href="test_8cpp.html#a45b838daf06782e49813fb7631e957ec">Drive</a>(<span class="keywordtype">int</span> snelheid, <span class="keywordtype">int</span> direction)
<a name="l00009"></a>00009 {
<a name="l00010"></a>00010         <span class="keywordtype">int</span> res = <a class="code" href="serial_8cpp.html#afcbe0bdca93dd392b104bf7c7775ba42">OpenComport</a>(<a class="code" href="test_8cpp.html#a031fc8d9a2aec0a2af2b3c9884e277e4">POORT</a>, 19200);
<a name="l00011"></a>00011         <span class="keywordtype">float</span> speed = <a class="code" href="test_8cpp.html#a5dd13af014b612f67220ddd841479c5b">MAXV</a>*snelheid*0.01;
<a name="l00012"></a>00012         <span class="keywordflow">if</span>(res == 1)
<a name="l00013"></a>00013         {
<a name="l00014"></a>00014                 printf(<span class="stringliteral">&quot;Error while opening comport\n&quot;</span>);
<a name="l00015"></a>00015                 <span class="keywordflow">return</span>;
<a name="l00016"></a>00016         }
<a name="l00017"></a>00017 
<a name="l00018"></a>00018         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[3];
<a name="l00019"></a>00019         buf[0]=(direction) ? 0xD6 : 0xD9;
<a name="l00020"></a>00020         buf[1] = speed;         <span class="comment">//0xD9 = forward, 0xD6 is achteruit</span>
<a name="l00021"></a>00021         buf[2] = speed;
<a name="l00022"></a>00022         res = <a class="code" href="serial_8cpp.html#af2a032058a335a76ef91d025ac63942b">SendBuf</a>(<a class="code" href="test_8cpp.html#a031fc8d9a2aec0a2af2b3c9884e277e4">POORT</a>, buf, 3);
<a name="l00023"></a>00023         <span class="keywordflow">if</span>(res != 1)
<a name="l00024"></a>00024         {
<a name="l00025"></a>00025                 <span class="keywordflow">if</span>(snelheid == 0)
<a name="l00026"></a>00026                         printf(<span class="stringliteral">&quot;Stopped\n&quot;</span>);
<a name="l00027"></a>00027                 <span class="keywordflow">else</span>
<a name="l00028"></a>00028                         printf(<span class="stringliteral">&quot;Going forward, speed %d\n&quot;</span>, (<span class="keywordtype">int</span>)speed);
<a name="l00029"></a>00029         }
<a name="l00030"></a>00030         <span class="keywordflow">else</span>
<a name="l00031"></a>00031                 printf(<span class="stringliteral">&quot;Error while trying to move.\n&quot;</span>);
<a name="l00032"></a>00032         <a class="code" href="serial_8cpp.html#a76b8f1bd6cb72a1e153df998c2742842">CloseComport</a>(<a class="code" href="test_8cpp.html#a031fc8d9a2aec0a2af2b3c9884e277e4">POORT</a>);
<a name="l00033"></a>00033 }
<a name="l00034"></a>00034 
<a name="l00035"></a><a class="code" href="test_8cpp.html#a64bbebeb63a1a4de9b3aa24c1650599e">00035</a> <span class="keywordtype">void</span> <a class="code" href="test_8cpp.html#a64bbebeb63a1a4de9b3aa24c1650599e">Rotate</a>(<span class="keywordtype">int</span> hoek, <span class="keywordtype">bool</span> clockwise, <span class="keywordtype">int</span> snelheid)
<a name="l00036"></a>00036 {
<a name="l00037"></a>00037         <span class="keywordtype">int</span> res = <a class="code" href="serial_8cpp.html#afcbe0bdca93dd392b104bf7c7775ba42">OpenComport</a>(<a class="code" href="test_8cpp.html#a031fc8d9a2aec0a2af2b3c9884e277e4">POORT</a>, 19200);
<a name="l00038"></a>00038         <span class="keywordtype">float</span> speed = <a class="code" href="test_8cpp.html#a5dd13af014b612f67220ddd841479c5b">MAXV</a>*snelheid*0.01;
<a name="l00039"></a>00039         
<a name="l00040"></a>00040         <span class="keywordflow">if</span>(res == 1)
<a name="l00041"></a>00041         {
<a name="l00042"></a>00042                 printf(<span class="stringliteral">&quot;Error while opening comport\n&quot;</span>);
<a name="l00043"></a>00043                 <span class="keywordflow">return</span>;
<a name="l00044"></a>00044         }
<a name="l00045"></a>00045 
<a name="l00046"></a>00046         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[3];
<a name="l00047"></a>00047 
<a name="l00048"></a>00048         <span class="keywordflow">if</span>(clockwise)
<a name="l00049"></a>00049                 buf[0] = 0xD5;
<a name="l00050"></a>00050         <span class="keywordflow">else</span>
<a name="l00051"></a>00051                 buf[0] = 0xDA;
<a name="l00052"></a>00052         buf[1] = speed;         <span class="comment">//0xD9 = forward, 0xD6 is achteruit</span>
<a name="l00053"></a>00053         buf[2] = speed;
<a name="l00054"></a>00054         res = <a class="code" href="serial_8cpp.html#af2a032058a335a76ef91d025ac63942b">SendBuf</a>(<a class="code" href="test_8cpp.html#a031fc8d9a2aec0a2af2b3c9884e277e4">POORT</a>, buf, 3);
<a name="l00055"></a>00055         <span class="keywordflow">if</span>(res != 1)
<a name="l00056"></a>00056                 printf(<span class="stringliteral">&quot;Rotating...\n&quot;</span>);
<a name="l00057"></a>00057         <span class="keywordflow">else</span>
<a name="l00058"></a>00058                 printf(<span class="stringliteral">&quot;Error while trying to rotate.\n&quot;</span>);
<a name="l00059"></a>00059         <a class="code" href="serial_8cpp.html#a76b8f1bd6cb72a1e153df998c2742842">CloseComport</a>(<a class="code" href="test_8cpp.html#a031fc8d9a2aec0a2af2b3c9884e277e4">POORT</a>);
<a name="l00060"></a>00060         <span class="comment">//sleep(2);</span>
<a name="l00061"></a>00061         <span class="comment">//Drive(0);</span>
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 }
<a name="l00064"></a>00064 
<a name="l00065"></a><a class="code" href="test_8cpp.html#a0ddf1224851353fc92bfbff6f499fa97">00065</a> <span class="keywordtype">int</span> <a class="code" href="besturing_test_8cpp.html#a6288eba0f8e8ad3ab1544ad731eb7667">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067 
<a name="l00068"></a>00068         
<a name="l00069"></a>00069         <span class="comment">//for(int i=0;i&lt;4;i++)</span>
<a name="l00070"></a>00070         <span class="comment">//{</span>
<a name="l00071"></a>00071                 <a class="code" href="test_8cpp.html#a45b838daf06782e49813fb7631e957ec">Drive</a>(50,1);
<a name="l00072"></a>00072                 sleep(1);
<a name="l00073"></a>00073                 <a class="code" href="test_8cpp.html#a45b838daf06782e49813fb7631e957ec">Drive</a>(50,0);
<a name="l00074"></a>00074                 sleep(1);
<a name="l00075"></a>00075                 <a class="code" href="test_8cpp.html#a64bbebeb63a1a4de9b3aa24c1650599e">Rotate</a>(30,1,50);
<a name="l00076"></a>00076                 usleep(300000);         
<a name="l00077"></a>00077         <span class="comment">//}</span>
<a name="l00078"></a>00078         <a class="code" href="test_8cpp.html#a45b838daf06782e49813fb7631e957ec">Drive</a>(0);
<a name="l00079"></a>00079 
<a name="l00080"></a>00080 }
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Gegenereerd op Do 19 Mei 2011 10:15:28 voor Robocup-denayer-project-a door&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>
